package com.shengsiyuan.reflect;

import java.lang.reflect.*;

public class Client2 {

	/**
	 * @param args
	 * @throws NoSuchMethodException
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 * @throws SecurityException
	 * @throws IllegalArgumentException
	 */
	public static void main(String[] args) throws IllegalArgumentException,
			SecurityException, InstantiationException, IllegalAccessException,
			InvocationTargetException, NoSuchMethodException {
		// TODO Auto-generated method stub
		Subject realSubject = new RealSubject();
		InvocationHandler handler = new DynamicSubject(realSubject);
		Subject subject = (Subject) Proxy.newProxyInstance(handler.getClass()
				.getClassLoader(), realSubject.getClass().getInterfaces(),
				handler);
		subject.request();
		Subject subject2 = (Subject) Proxy
				.getProxyClass(handler.getClass().getClassLoader(),
						realSubject.getClass().getInterfaces())
				.getConstructor(new Class[]{InvocationHandler.class}).newInstance(handler);
		subject2.request();

	}
}
